<template>
  <div id="integralListTopSearch">
    <h1 class="con-right-title">
      积分列表
    </h1>
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <!-- 输入搜索部分 -->
        <el-form-item label="积分状态" prop="integralStatus">
          <el-select
            class="short-input"
            v-model="formInline.integralStatus"
            placeholder="请选择积分状态"
            clearable
          >
            <el-option
              v-for="item in statusList"
              :key="item.dictLabel"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="small" label="已使用积分:">
          <el-input-number
            v-model.number="formInline.usedIntegralGe"
            size="mini"
            :min="0"
            :max="999999"
            :step="1"
            step-strictly
            :controls="false"
          ></el-input-number>
          -
          <el-input-number
            v-model.number="formInline.usedIntegralLe"
            size="mini"
            :min="0"
            :max="999999"
            :step="1"
            step-strictly
            :controls="false"
          ></el-input-number>
        </el-form-item>
        <el-form-item class="small" label="剩余积分:">
          <el-input-number
            v-model.number="formInline.surplusIntegralGe"
            size="mini"
            :min="0"
            :max="999999"
            :step="1"
            step-strictly
            :controls="false"
          ></el-input-number>
          -
          <el-input-number
            v-model.number="formInline.surplusIntegralLe"
            size="mini"
            :min="0"
            :max="999999"
            :step="1"
            step-strictly
            :controls="false"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="用户大鹏号" prop="dpAccount">
          <el-input
            v-model="formInline.dpAccount"
            placeholder="请输入大鹏号"
            size="small"
            class="numberInput"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="首次获取积分时间" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getDpNum } from '@/api/system/user'
export default {
  name: 'shareTopSearch',
  msg: '分享语管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          integralStatus: '', // 积分状态
          usedIntegralGe: undefined, // 已使用积分大于等于
          usedIntegralLe: undefined, // 已使用积分小于等于
          surplusIntegralGe: undefined, // 剩余积分大于等于
          surplusIntegralLe: undefined, // 剩余积分小于等于
          dpAccount: '', // 用户大鹏号
          startTime: '', // 开始时间
          endTime: '', // 结束时间
          createTime: []
        }
      }
    }
  },
  data() {
    return {
      // 视频状态
      statusList: [{ dictLabel: '全部', dictValue: '' }],
      rules: {
        dpAccount: {},
        uploadUserId: {},
        searchTitle: {},
        state: {},
        createTime: { type: 'array' }
      }
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },
  mounted() {
    this.getStatusList()
  },
  methods: {
    async getStatusList() {
      let data = await sysNormalDisable('integral_status', 'integralStatus')
      this.statusList = this.statusList.concat(data)
      /* this.setDefaultValue()*/
    },
    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.integralStatus = this.statusList[0].dictValue
      this.formInline.usedIntegralGe = undefined
      this.formInline.usedIntegralLe = undefined
      this.formInline.surplusIntegralGe = undefined
      this.formInline.surplusIntegralLe = undefined
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      this.setDefaultValue()
    }
  }
}
</script>

<style lang="less">
#integralListTopSearch {
  .small {
    .el-input-number--mini {
      width: 70px;
      margin-right: 5px;
      .el-input__inner {
        padding-left: 5px;
        padding-right: 5px !important;
      }
    }
  }
  .short-input {
    .el-input__inner {
      width: 100px !important;
    }
  }
}
</style>
